import os

fileName=["00","01","02","03","04","05","06","07","08","09"]
dataDict = {}


def getData():
    workerNu = 0
    taskNu = 0
    for file in fileName:
        with open("data_"+file+".txt","r")as f:
            for i in f.readlines():
                tempList = i.split()
                if len(tempList) == 4:
                    firstStr=i
                    workerNu += int(i.split()[0])
                    taskNu += int(i.split()[1])
                    umax = i.split()[2]
                else:
                    if int(tempList[0]) in dataDict:
                        dataDict[int(tempList[0])].append(tempList)
                        if len(dataDict[int(tempList[0])])!=10:
                            print(len(dataDict[int(tempList[0])]))
                    else:
                        dataDict.update({int(tempList[0]):[tempList]})
    print(workerNu,taskNu,umax)
    tempStr = str(workerNu)+" "+str(taskNu)+" "+umax+" "+str(workerNu+taskNu)+"\n"
    with open('qdata.txt','w') as f:
        f.write(tempStr)
        for timeid in sorted(dataDict):
            for item in dataDict[timeid]:
                outstr = ''
                for j in item:
                    outstr +=j+' '
                outstr+='\n'
                f.write(outstr)
    # for i in sorted(dataDict):
    #     print(i)

if __name__ == "__main__":
    getData()